package com.ruoyi.project.WxMoudle.Bases;

import com.google.common.collect.Maps;
import com.ruoyi.project.alipay.OtherUtils;
import com.ruoyi.project.alipay.WeChatWithdrawUtils;

import java.math.BigDecimal;
import java.util.Map;

/*提现的方法封装*/
public class PickMoney extends AppController{

    /*提现到零钱的方法*/
    public static Object toPickChange(String pickMoney, String openId, String OrderNum) throws Exception {
        //提现金额(单位:元)
        //元转换为分,微信支付已分为单位
        BigDecimal sumAmount = new BigDecimal(pickMoney);
        Map<String, String> map = Maps.newHashMap();
        //乘以100，转换为分
        BigDecimal transAmt = sumAmount.multiply(new BigDecimal(100));


        //订单号
        map.put("partner_trade_no", OrderNum);
        //随机字符串
        map.put("nonce_str", OtherUtils.getNonceStr().toString());

        //openid("c从数据库中查询")
        map.put("openid", openId);
        //金额
        map.put("amount", transAmt.toString());
        ////企业付款操作说明信息
        map.put("desc", "提现测试,钱就不返还了");

        //调用支付
        String returnInfo = WeChatWithdrawUtils.withdrawRequestOnce(map, 3000, 3000, true);
        Map<String, String> resultMap = OtherUtils.readStringXmlOut(returnInfo);

        if (resultMap.containsKey("result_code") && "SUCCESS".equals(resultMap.getOrDefault("result_code", ""))) {
            System.out.println("提现成功");
            System.out.println("返回结果：" + returnInfo);
            return writeResultRep("提现成功");
        } else {
            System.out.println("提现失败");
            System.out.println("返回结果：" + returnInfo);
            return writeResultFailure("提现失败");
        }
    }
}
